{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5903787a",
   "metadata": {},
   "source": [
    "# 数组"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90a62008",
   "metadata": {},
   "source": [
    "一维转二维"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5d882178",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "# We define two sequences x, y as numpy array\n",
    "# where y is actually a sub-sequence from x\n",
    "x = np.array([2, 0, 1, 1, 2, 4, 2, 1, 2, 0]).reshape(-1, 1)\n",
    "y = np.array([1, 1, 2, 4, 2, 1, 2, 0]).reshape(-1, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b6951665",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(10, 1) (8, 1)\n"
     ]
    }
   ],
   "source": [
    "print(x.shape, y.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "130bf7be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function __main__.<lambda>(x, y)>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from dtw import dtw\n",
    "\n",
    "manhattan_distance = lambda x, y: np.abs(x - y)\n",
    "manhattan_distance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a1ee3dea",
   "metadata": {},
   "outputs": [],
   "source": [
    "d, cost_matrix, acc_cost_matrix, path = dtw(x, y, dist=manhattan_distance)\n",
    "\n",
    "print(d)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
